package com.gc.server.controller;

import com.gc.server.entity.BannerEntity;
import com.gc.server.service.BannerService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.yf.consts.DaoConst;
import com.yf.response.R;

import javax.servlet.http.HttpServletResponse;


/**
 * 幻灯片Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Wed Jul 01 16:32:18 CST 2020
 */
@RestController
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    private BannerService bannerService;

    /**
     * 列表幻灯片
     */
    @SysLog("查看幻灯片")
    @RequestMapping("/list")
    @RequiresPermissions("banner:list")
    public R list(@RequestParam Map<String,Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<BannerEntity> bannerList = bannerService.queryList(params);
        return R.ok(new PageInfo(bannerList));
    }



    /**
     * 查看幻灯片
     */
    @SysLog("查看幻灯片")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("banner:info")
    public R info(@PathVariable("id") Long id) {
        BannerEntity banner = bannerService.get(id);

        return R.ok(banner);
    }

    /**
     * 保存幻灯片
     */
    @SysLog("保存幻灯片")
    @RequestMapping("/save")
    @RequiresPermissions("banner:save")
    public R save(BannerEntity banner) {
        bannerService.save(banner);

        return R.ok(banner);
    }

    /**
     * 修改幻灯片
     */
    @SysLog("修改幻灯片")
    @RequestMapping("/update")
    @RequiresPermissions("banner:update")
    public R update(BannerEntity banner) {
        bannerService.update(banner);

        return R.ok(banner);
    }

    /**
     * 删除幻灯片
     */
    @SysLog("删除幻灯片")
    @RequestMapping("/delete")
    @RequiresPermissions("banner:delete")
    public R delete(Long[]ids) {
        bannerService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有幻灯片
     */
    @SysLog("所有幻灯片")
    @RequestMapping("/all")
    public R queryAll (@RequestParam Map<String,Object> params) {

        List<BannerEntity> bannerList = bannerService.queryList(params);

        return R.ok(bannerList);
    }

    /***********自定义开始***********/
}
